//
//  YWAssetsInventoryDetailHeadTableViewCell.m
//  maintain
//
//  Created by 烟雨云渊 on 16/10/26.
//  Copyright © 2016年 ewin. All rights reserved.
//

#import "YWAssetsInventoryDetailHeadTableViewCell.h"
#import "YWMacro.h"
#import "Masonry.h"
#import "UIColor+CustomColors.h"

#import "YWAssetCheckRecord.h"
#import "YWHandler.h"
#import "YWBuildingManager.h"
#import "YWLocation.h"
#import "YWCommonTool.h"
#import "YYLabel.h"

@interface YWAssetsInventoryDetailHeadTableViewCell()
/*清点人*/
@property (nonatomic, strong) YYLabel * assetsManLabel;
/*位置*/
@property (nonatomic, strong) YYLabel * locationLabel;
/*清点时间*/
@property (nonatomic, strong) YYLabel * assetsTimeLabel;
/*备注*/
@property (nonatomic, strong) YYLabel * noteLabel;
@end

@implementation YWAssetsInventoryDetailHeadTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setUpSubviews];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setCheckRecord:(YWAssetCheckRecord *)checkRecord{
    _checkRecord = checkRecord;
    _assetsManLabel.attributedText = [YWCommonTool attributedTextWithFirstText:@"清点人: " firstColor:[UIColor customTextGrayBlackColor] secondText:_checkRecord.creator.userName?:@"无" secondColor:[UIColor customYellowColor] font:kContentFont];
    NSString * locationString = [[YWBuildingManager shareManager] areaLocationWithLocationId:_checkRecord.location.locationId];
    _locationLabel.attributedText = [YWCommonTool attributedTextWithFirstText:@"位置: " firstColor:[UIColor customTextGrayBlackColor] secondText:locationString.length>0?locationString:@"无" secondColor:[UIColor blackColor] font:kContentFont];
    NSString * assetTime = [YWCommonTool showTimeWithNormalFormatter:_checkRecord.createTime /1000];
    _assetsTimeLabel.attributedText = [YWCommonTool attributedTextWithFirstText:@"清点时间: " firstColor:[UIColor customTextGrayBlackColor] secondText:assetTime secondColor:[UIColor blackColor] font:kContentFont];
    NSString * note = _checkRecord.note.length>0?_checkRecord.note:@"无";
    _noteLabel.attributedText = [YWCommonTool attributedTextWithFirstText:@"备注: " firstColor:[UIColor customTextGrayBlackColor] secondText:note secondColor:[UIColor blackColor] font:kContentFont];
    
    self.locationLabel.preferredMaxLayoutWidth = self.locationLabel.frame.size.width;
    self.noteLabel.preferredMaxLayoutWidth = self.noteLabel.frame.size.width;
}

- (void)setUpSubviews{
    [self.assetsManLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).offset(6);
        make.left.mas_equalTo(self.contentView).offset(8);
        make.right.mas_equalTo(self.contentView).offset(-8);
    }];

    [self.locationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.assetsManLabel.mas_bottom).offset(6);
        make.left.mas_equalTo(self.contentView).offset(8);
        make.right.mas_equalTo(self.contentView).offset(-8);
    }];
    [self.assetsTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.locationLabel.mas_bottom).offset(6);
        make.left.mas_equalTo(self.contentView).offset(8);
        make.right.mas_equalTo(self.contentView).offset(-8);
    }];
    [self.noteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.assetsTimeLabel.mas_bottom).offset(6);
        make.left.mas_equalTo(self.contentView).offset(8);
        make.right.mas_equalTo(self.contentView).offset(-8);
        make.bottom.mas_equalTo(self.contentView).offset(-8);
    }];
}

//- (void)layoutSubviews{
//    [super layoutSubviews];
//    
//}

- (YYLabel *)assetsManLabel{
    if (!_assetsManLabel) {
        YYLabel *label = [[YYLabel alloc] init];
        _assetsManLabel = label;
        [self.contentView addSubview:_assetsManLabel];
    }
    return _assetsManLabel;
}

- (YYLabel *)locationLabel{
    if (!_locationLabel) {
        YYLabel *label = [[YYLabel alloc] init];
        label.numberOfLines = 0;
        _locationLabel = label;
        [self.contentView addSubview:_locationLabel];
    }
    return _locationLabel;
}

- (YYLabel *)assetsTimeLabel{
    if (!_assetsTimeLabel) {
        YYLabel *label = [[YYLabel alloc] init];
        _assetsTimeLabel = label;
        [self.contentView addSubview:_assetsTimeLabel];
    }
    return _assetsTimeLabel;
}

- (YYLabel *)noteLabel{
    if (!_noteLabel) {
        YYLabel *label = [[YYLabel alloc] init];
        label.numberOfLines = 0;
        _noteLabel = label;
        [self.contentView addSubview:_noteLabel];
    }
    return _noteLabel;
}

@end
